package com.huike.pmps.controller;

import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.Region;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@Api(tags = "战区管理")
@RestController
@RequestMapping("/api/regions")
public class RegionController {

    @Autowired
    RegionService regionService;


    @ApiOperation(value = "获取所有战区数据", httpMethod = "GET")
    @GetMapping("/all")
    public Result selectAll() {
        return regionService.selectAllRegion();
    }


    @ApiOperation(value = "按搜索条件分页查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "region", value = "战区", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "charge", value = "战区负责人", paramType = "query", dataType = "int")
    })
    @GetMapping
    public Result selectByCondition(PageInfo pageInfo, String region, String charge) {
        return regionService.selectByCondition(pageInfo, region, null, charge);
    }

    @ApiOperation(value = "新增战区/省区", httpMethod = "POST")
    @PostMapping
    public Result insertOne(Region region) {
        return regionService.insertOne(region);
    }

    @ApiOperation(value = "根据id修改战区/省区", httpMethod = "PUT")
    @PutMapping
    public Result updateById(Region region) {
        return regionService.updateById(region);
    }

    @ApiOperation(value = "根据id删除战区/或省区", httpMethod = "DELETE")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return regionService.deleteById(id);
    }

    @ApiOperation(value = "根据战区主键id,获取战区下的省区", httpMethod = "GET")
    @GetMapping("/{id}/provinces")
    public Result selectByParentId(@PathVariable("id") Integer parentId) {
        return regionService.selectByParentId(parentId);
    }

}
